from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel

class DDoSTopo(Topo):
    def build(self):
        switch = self.addSwitch('s1')
        victim = self.addHost('h1')
        attackers = [self.addHost(f'h{i}') for i in range(2, 6)]  # h2~h5为攻击者

        self.addLink(victim, switch)
        for attacker in attackers:
            self.addLink(attacker, switch)

if __name__ == '__main__':
    setLogLevel('info')
    net = Mininet(topo=DDoSTopo(), controller=RemoteController)
    net.start()
    CLI(net)
    net.stop()

def calculate_entropy(ip_list):
    counter = Counter(ip_list)
    total = len(ip_list)
    entropy = -sum((count/total) * math.log2(count/total) for count in counter.values())
return entropy

